package com.euc.springbootframework.controller.auth;


import com.euc.springbootframework.controller.base.RESTBaseController;
import com.euc.springbootframework.entity.Role;
import com.euc.springbootframework.entity.User;
import com.euc.springbootframework.service.base.RestBaseService;
import com.euc.springbootframework.service.auth.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@ResponseBody
@RequestMapping(value = "/role")
public class RoleController extends RESTBaseController<Role> {

    @Autowired
    RoleService roleService;

    @Override
    public RestBaseService<Role> getRestService() {
        return roleService;
    }

    @RequestMapping(value="/roles/{username}")
    @PreAuthorize(value = "hasAuthority('User')")
    public List<Role> findRolesByUsername(@PathVariable("username")String username){
        return roleService.findRolesByUsername(username);
    }
}
